#include "TextureCache.h"

#include <sstream>
#include <stddef.h>

TextureCache::TextureMap TextureCache::cache;

void TextureCache::clear()
{
    for (TextureMap::iterator it = cache.begin(); it != cache.end(); ++it)
    {
        delete (it->second);
    }
    cache.clear();
}

TextureCache::TextureCache()
{
}

TextureCache::~TextureCache()
{
}

void TextureCache::put(const std::string& key, Texture* texture)
{
    cache[key] = texture;
}

Texture* TextureCache::get(const std::string& key)
{
    if (has(key))
    {
        return cache[key];
    }
    return NULL;
}

bool TextureCache::has(const std::string& key)
{
    return cache.find(key) != cache.end();
}

std::string TextureCache::keyFromColor(const Color& color)
{
    std::ostringstream oss;
    oss << color.r << color.g << color.b << color.a;
    return oss.str();
}

std::string TextureCache::keySizeColor(const Size& size)
{
    std::ostringstream oss;
    oss << size.width << size.height;
    return oss.str();
}
